package com.xhs.zdl.demo.citypickerview;


import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.xhs.zdl.demo.R;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * A simple {@link Fragment} subclass.
 */
public class ListViewFragment extends Fragment {


    private View view;
    private ListView listview;
    private List<String> data;
    private Context context;
    private CitypickerviewAdapter adapter;
    private int type = 0;

    public ListViewFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_list_view, container, false);

        findView();
        initView();

        return view;
    }

    private void initView() {
        data = new ArrayList<>();
        adapter = new CitypickerviewAdapter(context, data);
        listview.setAdapter(adapter);
        listview.setOnItemClickListener(onItemClickListener);

        Object data = getArguments().get("data");
        if (data instanceof Map){
            Map<String, Object> map = (Map<String, Object>) data;
            type = 1;
//            disposeMap(map);
        }else if (data instanceof List){
            List<String> list = (List<String>) data;
            type = 2;
//            disposeList(list);
        }
    }

    private void findView() {
        listview = (ListView) view.findViewById(R.id.genged_listview);
    }

    AdapterView.OnItemClickListener onItemClickListener = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            if (type == 1){

            }
        }
    };

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.context = context;
    }
}
